#include<cstdio>
#include<cstring>
const int maxn=100010;
const int MAX=2100000000;
int a[maxn],s[maxn],r[maxn],l[maxn],w[maxn];
int n,t;
int main()
{
	while(scanf("%d",&n)&&n)
	{
		memset(a,0,sizeof(a));
		memset(r,0,sizeof(r));
		memset(l,0,sizeof(l));
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		a[0]=a[n+1]=-MAX;
		for(int i=1;i<=n;i++)
			l[i]=r[i]=i;
		for(int i=1;i<=n;i++)
			while(a[i]<=a[l[i]-1])
				l[i]=l[l[i]-1];
		for(int i=n;i>=1;i--)
			while(a[i]<=a[r[i]+1])
				r[i]=r[r[i]+1];
		long long ans=-1;
		for(int i=1;i<=n;i++)
		if(ans<((long long)a[i])*(r[i]-l[i]+1))
			ans=((long long)a[i])*(r[i]-l[i]+1);
		printf("%lld\n",ans);
	}
	return 0;
}



